package com.wanlian.router.storage;

import com.smart.android.storage.DataStorageSystem;
import com.wanlian.router.Frame;

/**
 * Created by Hyu on 2018/9/12.
 * Email: fvaryu@163.com
 */
public interface AppData {


    String APP_CONFIG_PREFS_FILE = "sp_app";

    AppData DEFAULT = new AppData() {
        @Override
        public boolean isFirstInstall() {
            return DataStorageSystem.get(Frame.getInstance().getAppContext(), APP_CONFIG_PREFS_FILE).readBoolean("_app_first_install", true);
        }

        @Override
        public void setFirstInstall(boolean firstInstall) {
            DataStorageSystem.get(Frame.getInstance().getAppContext(), APP_CONFIG_PREFS_FILE).write("_app_first_install", firstInstall);
        }

        @Override
        public boolean isShowIntro(int versionCode) {
            int code = DataStorageSystem.get(Frame.getInstance().getAppContext(), APP_CONFIG_PREFS_FILE).readInt("_app_version_code");
            return code != versionCode;
        }

        @Override
        public void setVersionCode(int versionCode) {
            DataStorageSystem.get(Frame.getInstance().getAppContext(), APP_CONFIG_PREFS_FILE).write("_app_version_code", versionCode);
        }

        @Override
        public long getServerSystemTime() {
            long date = DataStorageSystem.get(Frame.getInstance().getAppContext(), APP_CONFIG_PREFS_FILE).readLong("_app_server_system_time");
            if (date == 0) {
                date = System.currentTimeMillis();
            }
            return date;
        }

        @Override
        public void setServerSystemTime(long time) {
            DataStorageSystem.get(Frame.getInstance().getAppContext(), APP_CONFIG_PREFS_FILE).write("_app_server_system_time", time);
        }

        @Override
        public void setSkipVersion(String versionName) {
            DataStorageSystem.get(Frame.getInstance().getAppContext(), APP_CONFIG_PREFS_FILE).write("_app_skip_version", versionName);
        }

        @Override
        public boolean isSkipVersion(String versionName) {
            String code = DataStorageSystem.get(Frame.getInstance().getAppContext(), APP_CONFIG_PREFS_FILE).readString("_app_skip_version");
            return versionName.equals(code);
        }

        @Override
        public void put(String key, String value) {
            DataStorageSystem.get(Frame.getInstance().getAppContext(), APP_CONFIG_PREFS_FILE).write(key, value);
        }

        @Override
        public String get(String key) {
            return DataStorageSystem.get(Frame.getInstance().getAppContext(), APP_CONFIG_PREFS_FILE).readString(key);
        }

        @Override
        public void setIgnoreVersion(String version) {
            DataStorageSystem.get(Frame.getInstance().getAppContext(), APP_CONFIG_PREFS_FILE).write("_app.ignore_version", version);
        }

        @Override
        public String getIgnoreVersion() {
            return DataStorageSystem.get(Frame.getInstance().getAppContext(), APP_CONFIG_PREFS_FILE).readString("_app.ignore_version");
        }


        @Override
        public String getAccount() {
            return DataStorageSystem.get(Frame.getInstance().getAppContext(), APP_CONFIG_PREFS_FILE).readString("_app.user.account");
        }

        @Override
        public void setAccount(String account) {
            DataStorageSystem.get(Frame.getInstance().getAppContext(), APP_CONFIG_PREFS_FILE).write("_app.user.account", account);
        }

        @Override
        public String getSessionId() {
            return DataStorageSystem.get(Frame.getInstance().getAppContext(), APP_CONFIG_PREFS_FILE).readString("_app.sessionId");
        }

        @Override
        public void setSessionId(String sessionId) {
            DataStorageSystem.get(Frame.getInstance().getAppContext(), APP_CONFIG_PREFS_FILE).write("_app.sessionId", sessionId);
        }

        @Override
        public String getDomain() {
            return DataStorageSystem.get(Frame.getInstance().getAppContext(), APP_CONFIG_PREFS_FILE).readString("_app.domain");
        }

        @Override
        public void setDomain(String domain) {
            DataStorageSystem.get(Frame.getInstance().getAppContext(), APP_CONFIG_PREFS_FILE).write("_app.domain", domain);
        }
    };


    String getSessionId();
    void setSessionId(String sessionId);


    String getDomain();
    void setDomain(String domain);



    String getAccount();

    void setAccount(String account);


    boolean isFirstInstall();

    void setFirstInstall(boolean firstInstall);

    boolean isShowIntro(int versionCode);

    void setVersionCode(int versionCode);

    long getServerSystemTime();

    void setServerSystemTime(long time);

    void setSkipVersion(String versionName);

    boolean isSkipVersion(String versionName);

    void put(String key, String value);
    String get(String key);



    void setIgnoreVersion(String url);
    String getIgnoreVersion();
}
